﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace KPIS.GERP.GHRMS.DAL
{
    public class ConvertNullable
    {
        public Nullable<int> ConvertNullInt(Object o)
        {
            Nullable<int> result = (o == null ? null : (o.ToString().Length == 0 ? new Nullable<int>() : (Nullable<int>)Convert.ToInt32(o)));
                return result; 
        }

        public Nullable<double> ConvertNullDouble(Object o)
        {
            Nullable<double> result = (o == null ? null : (o.ToString().Length == 0 ? null : (Nullable<double>)Convert.ToDouble(o)));
            return result;
        }

        public Nullable<DateTime> ConvertNullDateTime(Object o)
        {
            Nullable<DateTime> result = (o == null ? null : (o.ToString().Length == 0 ? null : (Nullable<DateTime>)Convert.ToDateTime(o)));
            return result;
        }

        public Nullable<TimeSpan> ConvertNullTimeSpan(Object o)
        {
            Nullable<TimeSpan> result = (o == null ? null : (o.ToString().Length == 0 ? null : (Nullable<TimeSpan>)Convert.ToDateTime(o).TimeOfDay));
            return result;
        }
        public int ConvertToInt(Object o)
        {

            Nullable<int> result = (o == null ? null : (o.ToString().Length == 0 ? new Nullable<int>() : (Nullable<int>)Convert.ToInt32(o)));
            if (result == null)
                return -1;
            else
                return Convert.ToInt32(result);
        }
        public int ConvertToString(Object o)
        {

            Nullable<int> result = (o == null ? null : (o.ToString().Length == 0 ? new Nullable<int>() : (Nullable<int>)Convert.ToInt32(o)));
            if (result == null)
                return -1;
            else
                return Convert.ToInt32(result);
        }
        public int ConvertToDecimal(Object o)
        {

            Nullable<int> result  = (o == null ? null : (o.ToString().Length == 0 ? new Nullable<int>() : (Nullable<int>)Convert.ToDecimal(o)));
            return Convert.ToInt32(result);
        }


        //public Nullable<string> ConvertNullString(Object o)
        //{
        //    Nullable<string> result = (0 == null ? null : (o.ToString().Length == 0 ? null : (Nullable<string>)Convert.ToString(o)));
        //    return result;
        //}
    }
}
